import Vue from 'vue'
import {
	toast
} from "../utils/public.js"
// import store from '@/store/index.js'
//全局引入混用
Vue.mixin({
	data() {
		return {

		}
	},
	methods: {
		// 查看多张
		imgDuo(img, current) {
			let imgsArray = []
			imgsArray = img.split(",")
			uni.previewImage({
				current: current,
				urls: imgsArray,
				indicator: 'number',
				loop: true
			});
		},
		getIndexToken(){
			return;
		},
		getnavtoken(url){
			uni.navigateTo({
				url: url
			})
			if (!uni.getStorageSync('zfbtoken')) {
				let uid = uni.getStorageSync('uid')
				this.getLogoin(uid)
			} else {
				
			}
		},
		getLogin(pid,phone){
			let that = this
			uni.getUserProfile({
				desc: "获取用户名称，信息",
				success: (res1) => {
					console.log(res1.userInfo,'授权人微信信息') // 授权人微信信息
					uni.getProvider({
						service: 'oauth',
						success: function(res) {
							if (~res.provider.indexOf('weixin')) {
								uni.login({
									provider: 'weixin',
									success: (res2) => {
										uni.getUserInfo({
											provider: 'weixin',
											success: (info) => { //这里请求接口
												console.log(res2.code,'code');
												// 登录
												that.$request("Login/WeixCode", {
													data: {
														code:res2.code,
													},
													isLoad: false
												}).then(res4 => {
													console.log(res4)
													that.$request("Login/Login", {
														data: {
															open_id:res4.result.openid,
															username:res1.userInfo.nickName,
															image:res1.userInfo.avatarUrl,
															phone:phone,
															// sex:res1.userInfo.gender == 0?'1':'2',
															pid:pid?pid:'',
														},
														isLoad: false
													}).then(res5 => {
														// 存储token
														uni.setStorageSync('wxtoken',res5.token);
														uni.reLaunch({
															url: '/pages/tab/tabOne/tabOne'
														});
													})	
												})	
											}, 
											fail: () => {
												uni.showToast({
													title: "微信登录授权失败",
													icon: "none"
												});
											}
										})
					
									},
									fail: () => {
										uni.showToast({
											title: "微信登录授权失败",
											icon: "none"
										});
									}
								})
					
							} else {
								uni.showToast({
									title: '请先安装微信或升级版本',
									icon: "none"
								});
							}
						}
					});
				},
				fail: (err) => {
					console.log(err)
					uni.showToast({
						icon: "none",
						title: '用户拒绝获取'
					})
				}
			})
		},
		//过滤器   
		getorder(value) {
			switch (Number(value)) {
				case 1:
					return "待支付"
					break;
				case 2:
					return "待发货"
					break;
				case 3:
					return "使用中"
					break;
				case 4:
					return "申请退款"
					break;
				case 5:
					return "退款成功"
					break;
				case 6:
					return "退款失败"
					break;
				case 7:
					return "订单结束"
					break;
				case 8:
					return "审核中"
					break;
				case 9:
					return "待收货"
					break;
				case -1:
					return "已取消"
					break;
				default:
					return ""
			}
		},
		getnav(url, data) {
			if (data) {
				uni.navigateTo({
					url: url + "?data=" + encodeURIComponent(data)
				})
			} else {
				uni.navigateTo({
					url: url
				})
			}
		},
		getnav1(url, data) {
			if (data) {
				uni.navigateTo({
					url: url + "?data=" + data
				})
			} else {
				uni.navigateTo({
					url: url
				})
			}
		},
		gettoast(data) {
			toast({
				title: data
			})
		},
		getback(data) {
			setTimeout(()=>{
				uni.navigateBack({
					
				})
			},1500)
		},
		// 查看单张图片
		imgDan(img) {
			let imgsArray = [];
			imgsArray[0] = img
			uni.previewImage({
				current: 0,
				urls: imgsArray
			});
		},
		filterInput(val) {
			// 去掉特殊字符·
			return val.replace(/[^A-z0-9-\u4e00-\u9fa5]/, '')
		},
		timeShijian(value) {
			var date = new Date(parseInt(value));
			var month = date.getMonth() + 1;
			var hours = date.getHours();
			if (hours < 10)

				hours = "0" + hours;

			var minutes = date.getMinutes();

			if (minutes < 10)

				minutes = "0" + minutes;

			var time = hours + ":" + minutes;

			return time;
		},
		timeShijianall(value){
				var date = new Date(parseInt(value));
			
				//date.setTime(value);
			
				var month = date.getMonth() + 1;
			
				var hours = date.getHours();
			
				if (hours < 10)
			
					hours = "0" + hours;
			
				var minutes = date.getMinutes();
			
				if (minutes < 10)
			
					minutes = "0" + minutes;
			
				var time = date.getFullYear() + "-" + month + "-" + date.getDate() +
			
					" " + hours + ":" + minutes;
			
				return time;
		},
		timeShijianall11(value){
				var date = new Date(parseInt(value));
			
				//date.setTime(value);
			
				var month = date.getMonth() + 1;
			
				var hours = date.getHours();
			
				if (hours < 10)
			
					hours = "0" + hours;
			
				var minutes = date.getMinutes();
			
				if (minutes < 10)
			
					minutes = "0" + minutes;
			
				var time = date.getFullYear() + "年" + month + "月" + date.getDate() +'日'
			
			
				return time;
		},
	}
})
